<template>
  <div>
    <el-drawer :visible.sync="dialogVisible" :direction="direction" size="700px" :before-close="handleClose">
      <div slot="title" class="title">{{ $t('dingDanXiangQing') }}</div>
      <div class="demo-drawer__content" v-loading="loading">
        <div class="description" v-if="orderDatalist">
          <div class="title">{{ $t('yongHuXinXi') }}</div>
          <div class="acea-row">
            <div class="description-term">{{ $t('yongHuNiCheng') }}：{{ orderDatalist.nikeName }}</div>
            <div class="description-term">{{ $t('youXiang') }}：{{ orderDatalist.userEmail }}</div>
          </div>
          <el-divider></el-divider>
          <div class="title">{{ $t('shouHuoXinXi') }}</div>
          <div class="acea-row">
            <div class="description-term">{{ $t('shouHuoRen') }}：{{ orderDatalist.realName }}</div>
            <div class="description-term">{{ $t('shouHuoDianHua') }}：{{ orderDatalist.userPhone }}</div>
            <div class="description-term">{{ $t('shouHuoDiZhi') }}：{{ orderDatalist.userAddress }}</div>
            <div class="description-term">{{ $t('shouHuoYouXiang') }}：{{ orderDatalist.email }}</div>
          </div>
          <el-divider></el-divider>
          <div class="title">{{ $t('shangHuXinXi') }}</div>
          <div class="acea-row">
            <div class="description-term">{{ $t('shangHuId') }}：{{ orderDatalist.merId }}</div>
            <div class="description-term">{{ $t('shangHuMingCheng') }}：{{ orderDatalist.merName }}</div>
            <div class="description-term">
              {{ $t('shangHuLeiBie') }}：{{ orderDatalist.merIsSelf | selfTypeFilter }}
            </div>
          </div>
          <el-divider></el-divider>
          <div class="title">{{ $t('shangPinXinXi') }}</div>
          <div v-for="(item, index) in orderDatalist.orderInfo" :key="index" class="acea-row">
            <div class="description-term">{{ $t('shangPinMingCheng') }}：{{ item.productName }}</div>
            <div class="description-term">{{ $t('shangPinJiaGe') }}：{{ item.price }}</div>
            <div class="description-term">{{ $t('shangPinGuiGe') }}：{{ item.sku }}x{{ item.payNum }}</div>
            <div class="description-term">{{ $t('shangPinZhongLiang') }}：{{ item.weight }}</div>
            <div class="description-term">{{ $t('shangPinTiJi') }}：{{ item.volume }}</div>
            <div class="description-term">
              {{ $t('shangPinTuPian') }}：
              <div class="demo-image__preview mr10">
                <el-image :src="item.image" :preview-src-list="[item.image]" />
              </div>
            </div>
          </div>
          <el-divider></el-divider>
          <div class="title">{{ $t('dingDanXinXi') }}</div>
          <div class="acea-row">
            <div class="description-term">{{ $t('dingDanHao') }}：{{ orderDatalist.orderNo }}</div>
            <div class="description-term">{{ $t('zhuDingDanHao') }}：{{ orderDatalist.masterOrderNo }}</div>
            <div class="description-term" style="color: red">
              {{ $t('dingDanZhuangTai') }}：
              <span v-show="orderDatalist.isUserDel">{{ $t('yiShanChu') }}</span>
              <span v-show="orderDatalist.refundStatus === 3">{{ $t('yiTuiKuan') }}</span>
              <span v-show="orderDatalist.paid === false && orderDatalist.status === 0">{{ $t('weiZhiFu') }}</span>
              <span v-show="orderDatalist.status === 0">{{ $t('weiFaHuo') }}</span>
              <span v-show="orderDatalist.status === 1">{{ $t('daiShouHuo') }}</span>
              <span v-show="orderDatalist.status === 3">{{ $t('yiWanCheng') }}</span>
              <span v-show="orderDatalist.status === 9">{{ $t('yiQuXiao') }}</span>
            </div>
            <div class="description-term">
              {{ $t('zhiFuZhuangTai') }}：{{ orderDatalist.paid ? $t('yiZhiFu') : $t('weiZhiFu') }}
            </div>
            <div class="description-term">{{ $t('shangPinZongShu') }}：{{ orderDatalist.totalNum }}</div>
            <div class="description-term">{{ $t('shangPinZongJia') }}：{{ orderDatalist.proTotalPrice }}</div>
            <div class="description-term">{{ $t('zhiFuYouFei') }}：{{ orderDatalist.payPostage }}</div>
            <div class="description-term">{{ $t('youHuiQuanJinE') }}：{{ orderDatalist.couponPrice }}</div>
            <div class="description-term">{{ $t('shiJiZhiFu') }}：{{ orderDatalist.payPrice }}</div>
            <div class="description-term fontColor3" v-if="orderDatalist.refundPrice">
              {{ $t('tuiKuanJinE') }}：{{ orderDatalist.refundPrice }}
            </div>
            <div class="description-term">{{ $t('chuangJianShiJian') }}：{{ orderDatalist.createTime }}</div>
            <div class="description-term" v-if="orderDatalist.refundReasonTime">
              {{ $t('tuiKuanShiJian') }}：{{ orderDatalist.refundReasonTime }}
            </div>
            <div class="description-term">{{ $t('zhiFuFangShi') }}：{{ orderDatalist.payType }}</div>
            <div class="description-term">{{ $t('yongHuBeiZhu') }}：{{ orderDatalist.userRemark | filterEmpty }}</div>
            <div class="description-term">
              {{ $t('pingTaiBeiZhu') }}：{{ orderDatalist.platformRemark | filterEmpty }}
            </div>
            <div class="description-term">{{ $t('shangJiaBeiZhu') }}：{{ orderDatalist.merRemark | filterEmpty }}</div>
          </div>
          <template v-if="orderDatalist.deliveryName">
            <el-divider></el-divider>
            <div class="title">{{ $t('wuLiuXinXi') }}</div>
            <div class="acea-row">
              <div class="description-term">{{ $t('kuaiDiGongSi') }}：{{ orderDatalist.deliveryName }}</div>
              <div class="description-term">
                {{ $t('kuaiDiDanHao') }}：{{ orderDatalist.deliveryId }}
                <el-button
                  type="primary"
                  size="mini"
                  @click="openLogistics"
                  style="margin-left: 5px"
                  v-hasPermi="['admin:order:logistics:info']"
                  >{{ $t('wuLiuChaXun') }}</el-button
                >
              </div>
            </div>
          </template>
        </div>
      </div>
    </el-drawer>
    <el-dialog v-if="orderDatalist" :title="$t('tiShi')" :visible.sync="modal2" width="30%">
      <div class="logistics acea-row row-top">
        <div class="logistics_img"><img src="@/assets/imgs/expressi.jpg" /></div>
        <div class="logistics_cent">
          <span class="mb10">{{ $t('wuLiuGongSi') }}：{{ resultInfo.expName }}</span>
          <span>{{ $t('wuLiuDanHao') }}：{{ resultInfo.expNo }}</span>
          <span v-show="resultInfo.courierPhone">{{ $t('kuaiDiZhan') }}：{{ resultInfo.courierPhone }}</span>
          <span v-show="resultInfo.courierPhone">{{ $t('kuaiDiYuanDianHua') }}：{{ resultInfo.courierPhone }}</span>
        </div>
      </div>
      <div class="acea-row row-column-around trees-coadd">
        <div class="scollhide">
          <el-timeline :reverse="reverse">
            <el-timeline-item v-for="(item, i) in result" :key="i">
              <p class="time" v-text="item.AcceptTime"></p>
              <p class="content" v-text="item.AcceptStation"></p>
            </el-timeline-item>
          </el-timeline>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="modal2 = false">{{ $t('guanBi') }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { orderDetailApi, getLogisticsInfoApi } from '@/api/order';
export default {
  name: 'OrderDetail',
  props: {
    orderId: {
      type: String,
      default: 0,
    },
  },
  data() {
    return {
      direction: 'rtl',
      reverse: true,
      dialogVisible: false,
      orderDatalist: null,
      loading: false,
      modal2: false,
      result: [],
      resultInfo: {},
    };
  },
  mounted() {},
  methods: {
    handleClose() {
      this.dialogVisible = false;
    },
    openLogistics() {
      this.getOrderData();
      this.modal2 = true;
    },
    // 获取订单物流信息
    getOrderData() {
      getLogisticsInfoApi({ orderNo: this.orderId }).then(async (res) => {
        this.resultInfo = res;
        this.result = JSON.parse(res.logisticsInfo);
      });
    },
    getDetail(id) {
      this.loading = true;
      orderDetailApi({ orderNo: id })
        .then((res) => {
          this.orderDatalist = res;
          this.loading = false;
        })
        .catch(() => {
          this.orderDatalist = null;
          this.loading = false;
        });
    },
  },
};
</script>

<style scoped lang="scss">
.title {
  font-size: 36px;
}
.demo-drawer__content {
  padding: 0 30px;
}
.demo-image__preview {
  width: 35px;
  height: auto;
  display: inline-block;
}
.logistics {
  align-items: center;
  padding: 10px 0px;
  .logistics_img {
    width: 45px;
    height: 45px;
    margin-right: 12px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .logistics_cent {
    span {
      display: block;
      font-size: 12px;
    }
  }
}

.trees-coadd {
  width: 100%;
  height: 400px;
  border-radius: 4px;
  overflow: hidden;
  .scollhide {
    width: 100%;
    height: 100%;
    overflow: auto;
    margin-left: 18px;
    padding: 10px 0 10px 0;
    box-sizing: border-box;
    .content {
      font-size: 12px;
    }

    .time {
      font-size: 12px;
      color: #2d8cf0;
    }
  }
}

.title {
  margin-bottom: 14px;
  color: #303133;
  font-weight: 500;
  font-size: 14px;
}

.description {
  &-term {
    display: table-cell;
    padding-bottom: 5px;
    line-height: 20px;
    width: 50%;
    font-size: 12px;
    color: #606266;
  }
  ::v-deep .el-divider--horizontal {
    margin: 12px 0 !important;
  }
}
</style>
